package com.kmxd.ams.controller.jy;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.kmxd.ams.client.jy.IStatisticsSvc;
import com.kmxd.ams.client.jy.dto.StatisticsAddDTO;
import com.kmxd.ams.client.jy.dto.StatisticsEditDTO;
import com.kmxd.ams.client.jy.dto.StatisticsQueryDTO;
import com.kmxd.ams.client.jy.vo.StatisticsVO;
import com.kmxd.ams.core.log.annotation.AutoLog;
import com.kmxd.ams.core.result.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.Date;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 评价统计
 *
 * @author ZuoLG
 * @since 2023-10-16
 */
@RestController
@Tag(name = "统计评价")
@RequestMapping("/jy/statistics")
@AllArgsConstructor
public class StatisticsCtl {

  private IStatisticsSvc statisticsService;

  /** 月度统计 */
  @Operation(summary = "月度统计")
  @RequestMapping("/monthReport")
  @AutoLog(module = "统计评价", title = "月度统计")
  public R monthStatistics(StatisticsQueryDTO req) {
    req.setYear(ObjectUtil.defaultIfNull(req.getYear(), DateUtil.year(new Date())));
    return R.success(statisticsService.monthStatistics(req));
  }

  /** 年度统计 */
  @Operation(summary = "年度统计")
  @RequestMapping("/yearReport")
  @AutoLog(module = "统计评价", title = "年度统计")
  public R yearStatistics(StatisticsQueryDTO req) {
    req.setYear(ObjectUtil.defaultIfNull(req.getYear(), DateUtil.year(new Date())));
    return R.success(statisticsService.yearStatistics(req));
  }

  /** 利用评价统计 */
  @Operation(summary = "利用评价统计")
  @RequestMapping("/evaluateReport")
  @AutoLog(module = "统计评价", title = "利用评价统计")
  public R evaluateStatistics(StatisticsQueryDTO req) {
    req.setYear(ObjectUtil.defaultIfNull(req.getYear(), DateUtil.year(new Date())));
    return R.success(statisticsService.evaluateReport(req));
  }

  /** 新增 */
  @Operation(summary = "新增")
  @PostMapping("/add")
  @SaCheckPermission("jy:statistics:add")
  @AutoLog(module = "统计评价", title = "新增")
  public R<Void> add(@Validated @RequestBody StatisticsAddDTO req) {
    statisticsService.add(req);
    return R.success();
  }

  /** 修改 */
  @Operation(summary = "修改")
  @PostMapping("/edit")
  @SaCheckPermission("jy:statistics:edit")
  @AutoLog(module = "统计评价", title = "修改")
  public R<Void> edit(@Validated @RequestBody StatisticsEditDTO req) {
    statisticsService.edit(req);
    return R.success();
  }

  /** 删除 */
  @Operation(summary = "删除")
  @PostMapping("/remove")
  @SaCheckPermission("jy:statistics:remove")
  @AutoLog(module = "统计评价", title = "删除")
  public R<Void> remove(@RequestParam String ids) {
    statisticsService.remove(ids);
    return R.success();
  }

  /** 查看 */
  @Operation(summary = "查看")
  @GetMapping("/view")
  @AutoLog(module = "统计评价", title = "查看")
  public R<StatisticsVO> view(@RequestParam Long id) {
    return R.success(statisticsService.view(id));
  }
}
